﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Encodings
{
    class Encodings
    {
        public static string inputFile = "../../input.txt";
        public static string outputFile = "../../output.txt";

        static void Main()
        {
            StreamWriter writer = new StreamWriter(outputFile);
            using (writer)
            {
                StreamReader reader = new StreamReader(inputFile, Encoding.GetEncoding("windows-1251"));
                using (reader)
                {
                    string text = reader.ReadToEnd();
                    text = ChangeTextEncoding(text);
                    writer.Write(text);
                }
            }
        }

        private static string ChangeTextEncoding(string text)
        {
            Encoding dstEncodingFormat = Encoding.UTF8;
            Encoding srcEncodingFormat = Encoding.GetEncoding("windows-1251");
            byte[] originalByteString = srcEncodingFormat.GetBytes(text);
            byte[] convertedByteString = Encoding.Convert(srcEncodingFormat,
            dstEncodingFormat, originalByteString);
            string finalString = dstEncodingFormat.GetString(convertedByteString);
            return finalString;
        }
    }
}
